<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="socket.io.js"></script>
</head>
<body>
<input id="count" type="text">
<button onclick="send()">发送</button>

</body>
<script>
    const serverUri = "http://192.168.7.124:9011";

    let socket;

    connect();
    let socketid = '';

    function connect() {
        socket = io.connect(serverUri, {
            'force new connection': true
        });
        socket.on('connect', function () {
            writeMsg("连接成功");
            socketid = socket.id
            writeMsg(socketid)
            //如果发送字符串send("hello Server"); *需要修改服务端接收类型
            socket.emit("ServerReceive", {
                name: "client",
                message: "hello Server"
            }, (res) => {
                writeMsg('socketio服务器返回的数据：' + JSON.stringify(res))
            });
        });
        socket.on('ClientReceive', function (data) {
            writeMsg(data);
        });
        socket.on('sbwc', data => {
            writeMsg("识别完成：" + JSON.stringify(data));
        })
        socket.on('cfwc', data => {
            writeMsg("拆分完成：" + JSON.stringify(data));
        })
        socket.on('disconnect', function () {
            writeMsg("连接断开");
        });
    }

    function send() {
        let countInput = document.querySelector('#count')
        console.dir(countInput)
        let count = countInput.value
        let xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
                writeMsg("发送成功：" + xmlhttp.responseText)
            }
        }
        xmlhttp.open("GET", `http://192.168.7.124:9090/test?socketid=${socketid}&count=${count}`, true);
        xmlhttp.send();
    }

    function writeMsg(msg) {
        document.body.innerHTML += `<br>${msg}`
    }

</script>
</html>